package com.yang.servlet;

import com.yang.service.MenuService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

//点击菜单跳转到MenuListServlet
@WebServlet("/MenuListServlet")
public class MenuListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        try {
            MenuService menuService = new MenuService();
            Map<String, List> menus = menuService.listMenus();
            //拿到一级和二级菜单的集合
            request.setAttribute("menu1List",menus.get("menu1List"));
            request.setAttribute("menu2List",menus.get("menu2List"));
            //转发到admin_menu_list.jsp中
            request.getRequestDispatcher("admin_menu_list.jsp").forward(request,response);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
